<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use DB;
use Illuminate\Support\Facades\Hash;
use Config;
use Ixudra\Curl\Facades\Curl;
use Intervention\Image\Facades\Image;

class HomeController extends Controller
{
	
    public function eCard(Request $request){

        return view('eCard');
	}
	
	public function test(Request $request){
		
		$bgFile = './download/head/white.png';
		$downloadFile = './download/head/高耸.png';
		
		// open an image file
		$img = Image::make($bgFile);
		
		// and insert a watermark for example
		$img->insert($downloadFile, 'top-left', 5, 5);
		// finally we save the image as a new file
		$img->save('./download/test.png');
		print_r('nice');
		exit;
		if (!file_exists($downloadFile)){
			$url = "http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTJZsTu6LlDqxcTibZicuJxIVwAN5zBHcZ4GkvHGiaia4tFlvhWNUKzDTibuz6gygZXibfhia7wkOlwxD4LMw/132";
			Curl::to($url)->withContentType('image/png')->download($downloadFile);
			print_r('ok');
		}
		print_r('ok');
	}

	//店员登陆
	public function apiAdminLogin(Request $request){
        //$user=DB::table('admin_users')->where("phone",$request->phone)->where("sId",$request->sId)->first();
		$user=DB::table('admin_users')->where("username",$request->username)->first();
		if($user){
			if(Hash::check($request->password, $user->password)){
				$rst=array("status"=>1,"msg"=>'成功',"data"=>$user);
			}else{
				$rst=array("status"=>0,"msg"=>'密码错误');
			}
		}else{
			$rst=array("status"=>0,"msg"=>'用户名不存在');
			 
		}
		return response()->json($rst,200)->setEncodingOptions(320);
	}
	//店员修改密码
	public function apiAdminResetPassword(Request $request){
		$auInfo = DB::table('admin_users')->where('sId', $request->sId)->where('auCode', $request->auCode)->first();
		if($user){
			$password = Hash::make($request->password);
			DB::table('admin_users')->where('sId', $request->sId)->where('auCode', $request->auCode)->update(['password'=> $password,'name'=>$request->userName]);
			$rst=array("status"=>1,"msg"=>'成功');
		}else{
			$rst=array("status"=>0,"msg"=>'用户不存在');
			 
		}
		return response()->json($rst,200)->setEncodingOptions(320);
	}
	//会员登陆
	public function apiLogin(Request $request){
		$user=DB::table('member_users')->where("muMobile",$request->username)->first();
		if($user){
			if($request->password==$user->muPassword){
				$rst=array("status"=>1,"msg"=>'成功',"data"=>$user);
			}else{
				$rst=array("status"=>0,"msg"=>'密码错误');
			}
		}else{
			$rst=array("status"=>0,"msg"=>'用户名不存在');
			 
		}
		return response()->json($rst,200)->setEncodingOptions(320);
	}
}
